<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="myNewAjax()">提交</button>
    <script>
        var myNewAjax = function(url) {
            return new Promise((resolve, reject) => {
                var xhr = new XMLHttpRequest()
                xhr.open('get', url)
                xhr.send(url)
                xhr.onreadystatechange = function() {
                    if(xhr.status == '200' && xhr.readyState == 4) {
                        var json = JSON.parse(xhr.responseText)
                        resolve(json)
                    }
                    else if(xhr.readyState != 4 && xhr.status !=200) {
                        reject('err')
                    }
                }
            })
        }
        myNewAjax('http://www.baidu.com')
    </script>
</body>
</html>